namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class DesktopDefault : Page
    {
        [AccessedThroughProperty("btnLogin")]
        private Button _btnLogin;
        [AccessedThroughProperty("btnRegister")]
        private Button _btnRegister;
        [AccessedThroughProperty("chkRemember")]
        private CheckBox _chkRemember;
        [AccessedThroughProperty("lblError")]
        private Label _lblError;
        [AccessedThroughProperty("RequiredFieldValidator1")]
        private RequiredFieldValidator _RequiredFieldValidator1;
        [AccessedThroughProperty("RequiredFieldValidator2")]
        private RequiredFieldValidator _RequiredFieldValidator2;
        [AccessedThroughProperty("txtPassword")]
        private TextBox _txtPassword;
        [AccessedThroughProperty("txtUsername")]
        private TextBox _txtUsername;
        private object designerPlaceholderDeclaration;

        public DesktopDefault()
        {
            base.Init += new EventHandler(this.Page_Init);
            base.Load += new EventHandler(this.Page_Load);
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        public void Login(object s, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                if (ITUser.Authenticate(this.txtUsername.Text, this.txtPassword.Text))
                {
                    FormsAuthentication.RedirectFromLoginPage(this.txtUsername.Text, this.chkRemember.Checked);
                }
                else
                {
                    this.lblError.Text = "Invalid username or password";
                }
            }
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (this.Request.IsAuthenticated)
            {
                this.Response.Redirect("~/Issues/IssueList.aspx");
            }
        }

        public void Register(object s, EventArgs e)
        {
            this.Response.Redirect("Register.aspx");
        }

        protected virtual Button btnLogin
        {
            get
            {
                return this._btnLogin;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnLogin != null)
                {
                    this._btnLogin.Click -= new EventHandler(this.Login);
                }
                this._btnLogin = value;
                if (this._btnLogin != null)
                {
                    this._btnLogin.Click += new EventHandler(this.Login);
                }
            }
        }

        protected virtual Button btnRegister
        {
            get
            {
                return this._btnRegister;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnRegister != null)
                {
                    this._btnRegister.Click -= new EventHandler(this.Register);
                }
                this._btnRegister = value;
                if (this._btnRegister != null)
                {
                    this._btnRegister.Click += new EventHandler(this.Register);
                }
            }
        }

        protected virtual CheckBox chkRemember
        {
            get
            {
                return this._chkRemember;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._chkRemember != null)
                {
                }
                this._chkRemember = value;
                if (this._chkRemember != null)
                {
                }
            }
        }

        protected virtual Label lblError
        {
            get
            {
                return this._lblError;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lblError != null)
                {
                }
                this._lblError = value;
                if (this._lblError != null)
                {
                }
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator1
        {
            get
            {
                return this._RequiredFieldValidator1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator1 != null)
                {
                }
                this._RequiredFieldValidator1 = value;
                if (this._RequiredFieldValidator1 != null)
                {
                }
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator2
        {
            get
            {
                return this._RequiredFieldValidator2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator2 != null)
                {
                }
                this._RequiredFieldValidator2 = value;
                if (this._RequiredFieldValidator2 != null)
                {
                }
            }
        }

        protected virtual TextBox txtPassword
        {
            get
            {
                return this._txtPassword;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtPassword != null)
                {
                }
                this._txtPassword = value;
                if (this._txtPassword != null)
                {
                }
            }
        }

        protected virtual TextBox txtUsername
        {
            get
            {
                return this._txtUsername;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtUsername != null)
                {
                }
                this._txtUsername = value;
                if (this._txtUsername != null)
                {
                }
            }
        }
    }
}

